package ren.nearby.home.mvp;

import com.orhanobut.logger.Logger;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import ren.nearby.bean.beans.APIBean;
import ren.nearby.http.di.BaseObserver;
import ren.nearby.http.di.HttpApi;
import ren.nearby.http.di.RxResultHelper;
import ren.nearby.http.di.SchedulersCompat;
import ren.nearby.http.view.progress.DialogRequest;

/**
 * Created by Administrator on 2018/5/14 0014.
 */

public class FragmentActAction implements FragmentContract.Action {
    FragmentContract.View mView;  // 需要抽象出来
    @Inject
    HttpApi mApi;

    @Inject
    FragmentActAction() {
//        mApi = api;
    }

    @Override
    public void takeView(FragmentContract.View view) {
        Logger.e(mView == null ? " mView =  0 " : " mView = 1 ");
        Logger.e(mApi == null ? " mApi =  0 " : " mApi = 1 ");
        mView = view;
        if (mApi != null) {
//            mApi.dowApk();
        }
    }

    @Override
    public void dropView() {
        mView = null;
    }

    @Override
    public void test() {
        Logger.e("test");
        Observable observable = mApi.testAPI("1012002");


        BaseObserver baseObserver = new BaseObserver<APIBean>(mView.getContext()) {
            @Override
            public void onNext(APIBean bean) {
                Logger.e("onNext");
            }
        };
        observable.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
                .compose(RxResultHelper.handleResult44())
                .compose(SchedulersCompat.applyProgress(mView.getContext(), DialogRequest.TAG_REQUEST))//compose必须顺序要写对，得在handleResult后面
                .subscribe(baseObserver);
    }
}
